home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / OTPCX.ZIP / pcxload.pas < prev    next >
Pascal/Delphi Source File  |  1996-05-14  |  4KB  |  111 lines

  1. Program LoadPcx;                        { PCX Decoder by Vulture / OT }
  2.  
  3. Uses Crt;                               { Used units }
  4.  
  5. Procedure VideoMode(Mode: Byte); ASSEMBLER;  { Used to switch to gfx modes }
  6. Asm
  7.    mov  ah,00
  8.    mov  al,Mode
  9.    int  10h
  10. End;
  11.  
  12. Procedure SetColor(Color,R,G,B: Byte); ASSEMBLER; { Sets RGB values of color }
  13. Asm
  14.    mov    dx,3C8h
  15.    mov    al,[Color]
  16.    out    dx,al
  17.    inc    dx
  18.    mov    al,[R]
  19.    out    dx,al
  20.    mov    al,[G]
  21.    out    dx,al
  22.    mov    al,[B]
  23.    out    dx,al
  24. End;
  25.  
  26. Procedure DecodePcx(S:String);          { Decodes a pcx file to VGA }
  27. Var PcxPointer, Loop1: Word;            { Various variables }
  28.     Temp1, Temp2: Byte;                 { The bytes to read }
  29.     VgaPos: Integer;                    { Position on the screen (lineair) }
  30.     F: File;                            { File ;-) }
  31.     Colors: Array[0..767] of Byte;      { Array for all RGB values }
  32. Begin
  33.  
  34.   Assign(F,S);                          { Name of file }
  35.   Reset(F,1);                           { Open the PCX }
  36.  
  37.   Seek(F,FileSize(F)-768);              { Palette data starts here }
  38.   BlockRead(F,Colors,768);              { Read all RGB values at once }
  39.   For Loop1 := 0 to 255 Do              { Set all colors }
  40.   Begin
  41.     SetColor(Loop1,Colors[Loop1*3] shr 2,Colors[Loop1*3+1] shr 2,Colors[Loop1*3+2] shr 2);
  42.   End;
  43.  
  44.   PcxPointer := 129;                    { Ignore header }
  45.   VgaPos := 0;                          { Start of VGA segment }
  46.   Seek(F,128);
  47.  
  48.   While (PcxPointer <= (FileSize(F)-128-768)) Do { No header & palette data }
  49.   Begin
  50.     BlockRead(F,Temp1,1);               { Read a byte from .pcx (from disk) }
  51.     Inc(PcxPointer);
  52.     If ((Temp1 AND 192) = 192) then
  53.     Begin                               { Compressed }
  54.       BlockRead(F,Temp2,1);             { Read the next byte }
  55.       Inc(PcxPointer);
  56.       For Loop1 := 1 to (Temp1 AND 63) Do     { Set loop counter }
  57.       Begin
  58.         Asm
  59.           mov   ax,$0a000
  60.           mov   es,ax
  61.           mov   di,VgaPos
  62.           mov   al,Temp2
  63.           mov   byte ptr es:[di],al
  64.         End;
  65.         Inc(VgaPos);
  66.       End;
  67.     End
  68.     Else
  69.     Begin                               { No compression, plot byte }
  70.       Asm
  71.         mov   ax,$0a000
  72.         mov   es,ax
  73.         mov   di,VgaPos
  74.         mov   al,Temp1
  75.         mov   byte ptr es:[di],al
  76.       End;
  77.       Inc(VgaPos);
  78.     End;
  79.   End;
  80.   Close(F);                             { Close the file }
  81. End;
  82.  
  83. Begin
  84.   VideoMode($13);
  85.   DecodePcx('PcxLoad.pcx');
  86.   Readkey;
  87.   VideoMode($3);
  88.   Writeln('▄  ▄▄  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄  ▄▄  ▄');
  89.   Writeln('                    - An Outlaw Triad Production (c) 1996 -');
  90.   Writeln;
  91.   Writeln('                             Code∙∙∙∙∙∙∙∙∙∙Vulture');
  92.   Writeln('                             Gfx∙∙∙∙∙∙∙∙∙∙∙∙∙Xotic');
  93.   Writeln;
  94.   Writeln('                            -=≡ Outlaw Triad Is ≡=-');
  95.   Writeln;
  96.   Writeln('  Vulture(code) ■ Dazl(artist) ■ Troop(sysop) ■ Xplorer(artist) ■ Inopia(code) ');
  97.   Writeln;
  98.   Writeln('▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄');
  99. End.
  100.  
  101.  
  102. {
  103.   Note:
  104.  
  105.   You can speed up this decoder quite a bit by using more assembler code
  106.   and by reading the entire pcxdata into memory. In this example we read
  107.   the pcx byte per byte from disk while you should read all data at once
  108.   and decode the pcx from memory.
  109.  
  110.        - Vulture / Outlaw Triad -
  111. }